package com.msg.test;

import com.msg.test.model.MsgConfig;
import com.msg.test.util.MsgUtil;

/**
 * Created by Administrator on 2017/10/19 0019.
 */
public class SendMsg {
    public static boolean sendMsg(String msg,String mobile){
        try{
            if (msg.getBytes("utf-8").length <140){//短短信
                boolean result = MessageService.sendShortMsg(msg,mobile);
                int count  = 0;
                while (!result){
                    count++;
                    result = MessageService.sendShortMsg(msg,mobile);
                    if (count >= (MsgConfig.getConnectCount() -1)){ //如果再次连接次数超过两次则终止连接
                        break;
                    }
                }
            }else{
                boolean result = MessageService.sendLongMsg(msg,mobile);
                int count = 0;
                while (!result){
                    count++;
                    result = MessageService.sendLongMsg(msg,mobile);
                    if (count >= (MsgConfig.getConnectCount() - 1)){
                        break;
                    }
                }
            }
            return true;
        }catch (Exception ex){
            return false;
        }
    }
}
